home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wink / source / rsb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  16.0 KB  |  684 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <ctype.h>
  4. #include    "defs.h"
  5. #ifdef  TOWNS
  6. #include    <egb.h>
  7. #include    <fmc.h>
  8. #include    "rsb.h"
  9. #endif
  10.  
  11. #define    MENU_MAX    11
  12. #define    M_SJIS        0
  13. #define    M_EUC        1
  14. #define M_JIS        2
  15.  
  16. extern UCHAR *cvram;
  17. extern char  *SPCSTR;
  18. extern int   Line_no;
  19. extern short ReWrt_flg;
  20. extern int   TrmCol;
  21. extern int   DspCnt;
  22.  
  23. extern char *kanji_chk();
  24. extern BOOL Input();
  25. extern void Dmy_form();
  26. extern void wrtstr();
  27. extern void Soft_Timer();
  28. extern int  kbhit();
  29. extern int  Get_key();
  30. extern void gtime();
  31. extern void BakPut();
  32. extern void Dsp_vram();
  33. extern int  Sel_menu();
  34. extern void Dsp_free();
  35. extern int  strlen();
  36. extern void strcpy();
  37. extern void Dsp_vram_flash();
  38. extern void BP_Term_ENQ();
  39. extern void BP_DLE_Seen();
  40. extern void ins_chr();
  41. extern void Set_vram();
  42. extern void Del_buf();
  43. extern void Cur_btm_file();
  44. extern int  File_sel();
  45. extern void Cut_buf();
  46. extern int  Undo_cpy();
  47. extern void memset();
  48. extern int  Con_init();
  49. extern void CD_menu();
  50. extern void Con_end();
  51. extern void Dsp_PFKEY();
  52.  
  53.        int  port=0,bps=0x05;
  54. static int  mode=0x11,brk=0,swait=0,KanMod=0;
  55. static int  Down_flg=FALSE,Line_flg=FALSE,Line_X=0;
  56. static FILE *Down_fp=NULL;
  57. static int  Flaing=FALSE;
  58. static unsigned brktime[]={ 25,50,100,200 };
  59. static int  swtime[]={1,5000,10000,20000,50000 };
  60. static RSB_PARA para;
  61.  
  62. #include    "xmodem.c"
  63.  
  64. #ifdef    TOWNS
  65. void    Test_RSB_mode()
  66. {
  67.     static short flg=FALSE;
  68.  
  69.     if ( flg != FALSE )
  70.     return;
  71.  
  72.     flg = TRUE;
  73.     RSB_rdpara(port,(char *)¶);
  74.     mode = para.mode;           /*  通信モード           */
  75.     bps = para.baud;            /*  ボーレート          */
  76. }
  77. int        RSB_init(pt,md,bp)
  78. int        pt,md,bp;
  79. {
  80.     int        er;
  81.  
  82.     para.mode = md;             /*  通信モード           */
  83.     para.baud = bp;             /*  ボーレート          */
  84.     para.rbuf = 0;              /*  受信バッファアドレス */
  85.     para.stime = 500;           /* 送信タイムアウト     */
  86.     para.rtime = 500;           /* 受信タイムアウト     */
  87.     para.rinfbuf = 0;           /*  受信通知アドレス     */
  88.     para.extmode = 0;           /*  拡張モード           */
  89.     para.xon = 0x11;            /*  XONコード            */
  90.     para.xoff = 0x13;           /*  XOFFコード           */
  91.  
  92.     RSB_dtr(pt,1);    /* DTR信号の保持 */
  93.     RSB_close(pt);
  94.     if ( (er = RSB_setpara(pt,(char *)¶)) == 0 )
  95.     er = RSB_open(pt);
  96.     return er;
  97. }
  98. #endif
  99.  
  100. /*********************************************************
  101. 012345678901234567890123456789012345678901234567890123
  102.           1         2         3         4         5
  103.            *     *     *     *     *     *     *
  104. ポ-トNo.    0     1     2     3     4
  105. 速  度     300   600   1200  2400  4800  9600  19200
  106. ビット長     7ビット 8ビット
  107. パリティ-     無し  偶数  奇数
  108. ストップビット  1ビット 2ビット
  109. フロ-制御    無し  XON/OFF
  110. ブレ-ク時間  250ms 500ms 1sec  2sec
  111. 文字色     青色  赤色  紫色  緑色  水色  黄色  白色
  112. 文字制御   有り  無し  表示
  113. 改行待ち   無し  50ms  100ms 200ms 500ms
  114. 漢字コ-ド SJIS  EUC   JIS
  115. **********************************************************/
  116. void    Set_RSB_mode(x,y)
  117. int    x,y;
  118. {
  119.     unsigned int ec;
  120.     int    i,n,no,ch,cl,fg;
  121.     char   tmp[160];
  122.     static int  pt,bp,bit,party,stop,xfls,br,col,ctl,swt,km;
  123.     static struct {
  124.     int     *flg_mn;
  125.     int     max_mn;
  126.     char    *ttl_mn;
  127.     char    *sub_mn[8];
  128.     } MODE_menu[]={
  129. { &pt,5,"ポ-トNo.   ","0","1","2","3","4" },
  130. { &bp,7,"速  度    ","300","600","1200","2400","4800","9600","19200"},
  131. { &bit,2,"ビット長    ","7ビット","8ビット" },
  132. { &party,3,"パリティ-    ","なし","奇数","偶数" },
  133. { &stop,2,"ストップビット ","1ビット","2ビット" },
  134. { &xfls,2,"フロ-制御   ","なし","あり" },
  135. { &br,4,"ブレ-ク時間 ","250ms","500ms","1sec","2sec" },
  136. { &col,7,"文字色    ","青色","赤色","紫色","緑色","水色","黄色","白色" },
  137. { &ctl,3,"文字制御  ","有り","無し","表示" },
  138. { &swt,5,"改行WAIT  ","無し","50ms","100ms","200ms","500ms" },
  139. { &km, 2,"漢字コ-ト   ","SJIS","EUC","JIS" }
  140.     };
  141.  
  142.     pt = port;
  143.     bp = bps;
  144.     bit = ((mode & 0x01) == 0 ? 0 : 1);
  145.     party = ((mode & 0x02) == 0 ? 0 : ((mode & 0x04) == 0 ? 1 : 2));
  146.     stop = ((mode & 0x08) == 0 ? 0 : 1);
  147.     xfls = ((mode & 0x10) == 0 ? 0 : 1);
  148.     br = brk;
  149.     col = TrmCol-1;
  150.     ctl = DspCnt;
  151.     swt = swait;
  152.     km = KanMod;
  153.  
  154.     Dmy_form(tmp,54,0x98,0x95,0x99); 
  155.     wrtstr(tmp,x,y,0x07);
  156.     Dmy_form(tmp,54,0x96,0x20,0x96); 
  157.     for ( i = 0 ; i < MENU_MAX ; i++ )
  158.     wrtstr(tmp,x,y+i+1,0x07);
  159.     Dmy_form(tmp,54,0x9A,0x95,0x9B); 
  160.     wrtstr(tmp,x,y+MENU_MAX+1,0x07);
  161.     x += 2; y += 1;
  162.  
  163.     for ( fg = FALSE,no = 0 ; fg == FALSE ; ) {
  164.     for ( i = 0 ; i < MENU_MAX ; i++ ) {
  165.         if ( i == no ) cl = 0x14; else cl = 0x07;
  166.         wrtstr(MODE_menu[i].ttl_mn,x,y+i,cl);
  167.         for ( n = 0 ; n < MODE_menu[i].max_mn ; n++ ) {
  168.         if ( n == *(MODE_menu[i].flg_mn) ) cl = 0x14; else cl = 0x07;
  169.         wrtstr(MODE_menu[i].sub_mn[n],x+11+n*6,y+i,cl);
  170.         }
  171.     }
  172.     ch = Get_key(&ec);
  173.     if ( ch == '\x1B' || ec == 0x7200 )
  174.         goto ENDOF;
  175.         else if ( ch == '\x0D' || ec == 0x7300 )
  176.         break;    
  177.     else if ( ch == ' ' || ch == '\x1F' ) {
  178.         if ( ++no >= MENU_MAX )
  179.         no = 0;
  180.     } else if ( ch == '\x08' || ch == '\x1E' ) {
  181.         if ( --no < 0 )
  182.         no = MENU_MAX-1;
  183.     } else if ( ch == '\x1C' ) {
  184.         *(MODE_menu[no].flg_mn) += 1;
  185.         if ( *(MODE_menu[no].flg_mn) >= MODE_menu[no].max_mn )
  186.         *(MODE_menu[no].flg_mn) = 0;
  187.     } else if ( ch == '\x1D' ) {
  188.         *(MODE_menu[no].flg_mn) -= 1;
  189.         if ( *(MODE_menu[no].flg_mn) < 0 )
  190.         *(MODE_menu[no].flg_mn) = MODE_menu[no].max_mn - 1;
  191.     }
  192.     }
  193.     mode = 0;
  194.     if ( bit != 0 ) mode |= 0x01;
  195.     if ( party == 1 ) mode |= 0x02;
  196.     if ( party == 2 ) mode |= 0x06;
  197.     if ( stop != 0 ) mode |= 0x08;
  198.     if ( xfls != 0 ) mode |= 0x10;
  199.     if ( pt != port ) {
  200.     RSB_close(port);
  201.     port = pt;
  202.     }
  203.     bps = bp;
  204.     brk = br;
  205.     TrmCol = col+1;
  206.     DspCnt = ctl;
  207.     swait = swt;
  208.     RSB_init(port,mode,bps);
  209.     KanMod = km;
  210. ENDOF:
  211. #ifdef    TOWNS
  212.     Dsp_vram_flash();
  213. #endif
  214.     Dsp_vram(cvram);
  215.     Dsp_free();
  216. }
  217. int jis2sjis(chr)
  218. unsigned int chr;
  219. {
  220.     int    hi,lo;
  221.  
  222.     hi=(chr >> 8)&0xff;
  223.     lo=chr & 0xff;
  224.     if ( (hi & 1) != 0 )
  225.     lo += 0x1F;
  226.     else
  227.     lo += 0x7D;
  228.     if ( lo >= 0x7F )
  229.     lo++;
  230.     hi = (hi - 0x21 >> 1) + 0x81;
  231.     if ( hi > 0x9F )
  232.     hi += 0x40;
  233.     return (hi << 8 | lo);
  234. }
  235. int sjis2jis(chr)
  236. unsigned int chr;
  237. {
  238.     int    hi,lo;
  239.  
  240.     hi=(chr >> 8)&0xff;
  241.     lo=chr & 0xff;
  242.     hi -= ( hi <= 0x9f) ? 0x71 : 0xb1;
  243.     hi = hi * 2 +1;
  244.     if ( lo > 0x7f )
  245.         lo--;
  246.     if ( lo >= 0x9e ) {
  247.         lo -= 0x7d;
  248.         hi++;
  249.     }
  250.     else
  251.         lo -= 0x1f;
  252.     return (hi << 8 | lo);
  253. }
  254. void    recv_chk()
  255. {
  256.     int        x,y,i,bl,len,ch;
  257.     unsigned int st;
  258.     static int  EucFlg=0,bch=0;
  259.     static char tmp[1024];
  260.  
  261.     RSB_read(port,&len);
  262.     if ( len <= 0 )
  263.     return;
  264.     if ( len > 1024 ) len = 1024;
  265.     for ( bl = i = 0 ; i < len ; i++ ) {
  266.     if ( EucFlg != 2 )
  267.         RSB_receive(port,&ch,&st);
  268.         if ( ch == 0x05 ) { /* ENQ Then B Plus Protocol Start ? */
  269.         BP_Term_ENQ();
  270.         break;
  271.     }
  272.         if ( ch == 0x10 ) { /* DLE Then B Plus Protocol Start ? */
  273.         BP_DLE_Seen();
  274.         break;
  275.     }
  276.  
  277.     switch(KanMod) {
  278.     case M_EUC:
  279.         switch(EucFlg) {
  280.         case 0:
  281.         if ( (ch & 0x80) != 0 ) {
  282.             bch = ch;
  283.             EucFlg = 1;
  284.             continue;
  285.         }
  286.         break;
  287.         case 1:
  288.         if ( (ch & 0x80) != 0 ) {
  289.             ch = ((bch << 8) | ch) & 0x7F7F;
  290.             ch = jis2sjis(ch);
  291.             bch = ch & 0xFF;
  292.             ch >>= 8;
  293.         } else {
  294.             x = ch;
  295.             ch = bch;
  296.             bch = x;
  297.         }
  298.         EucFlg = 2; 
  299.         break;
  300.         case 2:
  301.         ch = bch;
  302.         EucFlg = 0;
  303.         break;
  304.         }
  305.         break;
  306.     }
  307.  
  308.     BakPut(ch);
  309.     if ( ch != '\0' && ch != '\x0D' ) {
  310.         if ( ch == '\x0A' )
  311.         tmp[bl++] = 0x0D;
  312.         tmp[bl++] = ch;
  313.     }
  314.         if ( Down_fp != NULL && ch != '\x08' && ch != '\0' )
  315.         fputc(ch,Down_fp);
  316.     }
  317.     Dsp_vram(cvram);
  318.     if ( Down_flg != FALSE ) {
  319.     x = Cur_X; y = Cur_Y;
  320.         ins_chr(tmp,bl);
  321.     Set_vram();
  322.     Dsp_free();
  323.     Cur_X = x; Cur_Y = y;
  324.     }
  325. }
  326. void    Send_char(ch)
  327. int    ch;
  328. {
  329.     unsigned st;
  330.     static int BakKan='\0';
  331.     static int SftIn=FALSE;
  332.  
  333.     ch &= 0xff;
  334.     switch(KanMod) {
  335.     case M_SJIS: /* SJIS */
  336.     RSB_send(port,ch,&st);
  337.     break;
  338.     case M_JIS: /* JIS */
  339.     if ( BakKan != '\0' ) {
  340.         if ( iskanji2(ch) ) {
  341.         ch = sjis2jis((BakKan << 8) | ch);
  342.         if ( SftIn == FALSE ) {
  343.                 RSB_send(port,0x1b,&st);
  344.                 RSB_send(port,'$',&st);
  345.                 RSB_send(port,'B',&st);
  346.             SftIn=TRUE;
  347.         }
  348.             RSB_send(port,ch >> 8,&st);
  349.             RSB_send(port,ch & 0xff,&st);
  350.         BakKan = '\0';
  351.         return;
  352.         }
  353.         RSB_send(port,BakKan,&st);
  354.         RSB_send(port,ch,&st);
  355.         BakKan = '\0';
  356.     } else if ( iskanji(ch) ) {
  357.         BakKan = ch;
  358.         return;
  359.     } else {
  360.         if ( SftIn != FALSE ) {
  361.             RSB_send(port,0x1b,&st);
  362.             RSB_send(port,'(',&st);
  363.             RSB_send(port,'J',&st);
  364.         SftIn=FALSE;
  365.         }
  366.         RSB_send(port,ch,&st);
  367.     }
  368.     break;
  369.     case M_EUC: /* EUC */
  370.     if ( BakKan != '\0' ) {
  371.         if ( iskanji2(ch) ) {
  372.         ch = sjis2jis((BakKan << 8) | ch) | 0x8080;
  373.             RSB_send(port,ch >> 8,&st);
  374.             RSB_send(port,ch & 0xff,&st);
  375.         BakKan = '\0';
  376.         return;
  377.         }
  378.         RSB_send(port,BakKan,&st);
  379.         RSB_send(port,ch,&st);
  380.         BakKan = '\0';
  381.     } else if ( iskanji(ch) ) {
  382.         BakKan = ch;
  383.         return;
  384.     } else
  385.         RSB_send(port,ch,&st);
  386.     break;
  387.     }
  388.     if ( ch == 0x0D && swait != 0 )
  389.     Soft_Timer(swtime[swait]);
  390. }
  391. void    Dsp_RSBKEY()
  392. {
  393.     int     i;
  394.     static char *menu[]={
  395.     " 設定 "," 入力 "," AUTO ","      ","CD演奏",
  396.     "ダウン","アップ"," ブレ-ク"," 終了 "," 中断 " };
  397.  
  398.     for ( i = 0 ; i < 10 ; i++ )
  399.         wrtstr(menu[i],i*7+(i/5),MENU_Y,0x16);
  400. }
  401. void    Down_load()
  402. {
  403.     int    x,y;
  404.     char   tmp[80];
  405.     static int  no=ERR;
  406.     static char *menu[]={
  407.     "1 編集バッファに (新規) ",
  408.     "2 編集バッファに (追加) ",
  409.     "",
  410.     "3 ファイルに(新規/追加) ",
  411.     "",
  412.     "4 X-Modemでダウンする   ",
  413.     "5 X-Modemでダウン(高速) ",
  414.     NULL };
  415.  
  416.     wrtstr(SPCSTR,30,1,0x1F);
  417.     if ( Down_flg != FALSE || Down_fp != NULL ) {
  418.     if ( Down_fp != NULL ) {
  419.         fputc('\x1A',Down_fp);
  420.         fclose(Down_fp);
  421.         Down_fp = NULL;
  422.     }
  423.     Down_flg = FALSE;
  424.     wrtstr("                  ",32,0,0x1F);
  425.     return;
  426.     }
  427.  
  428.     if ( Sel_menu(menu,25,2,&no) != FALSE )
  429.     goto ENDOF;
  430.  
  431.     if ( no == 0 ) {
  432.     Del_buf(0l,btm_ptr);
  433.     top_ptr = lin_ptr = ent_ptr = btm_ptr = 0;
  434.     Line_no = 0;
  435.         Down_flg = TRUE;
  436.     } else if ( no == 1 ) {
  437.         x = Cur_X; y = Cur_Y;
  438.         Cur_btm_file();
  439.         Cur_X = x; Cur_Y = y;
  440.         Down_flg = TRUE;
  441.     } else if ( no == 2 ) {
  442.     tmp[0] = '\0';
  443.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  444.         goto ENDOF;
  445.     if ( (Down_fp = fopen(tmp,"ab+")) == NULL ) {
  446.         wrtstr("(ファイルがオ-プン出来ません)",30,1,0x12);
  447.         goto ENDOF;
  448.     }
  449.     } else if ( no == 3 || no == 4 ) {
  450.     tmp[0] = '\0';
  451.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  452.         goto ENDOF;
  453.     Flaing = (no == 3 ? FALSE : TRUE);
  454.         RSB_init(port,mode & 0xEF,bps);
  455.     Down_Xmodem(tmp);
  456.         RSB_init(port,mode,bps);
  457.     goto ENDOF;
  458.     }
  459.     wrtstr("ダウンロ-ド実行中",32,0,0x15);
  460. ENDOF:
  461.     Dsp_vram(cvram);
  462.     Dsp_free();
  463. }
  464. void    Up_load()
  465. {
  466.     int        ch,i,n,ct;
  467.     unsigned int ec;
  468.     FILE   *fp;
  469.     char   tmp[256];
  470.     char   *p;
  471.     LONG   ptr,sz;
  472.     static int  no=ERR;
  473.     static char *menu[]={
  474.     "1 編集バッファをアップ  ",
  475.     "2 Undoバッファをアップ  ",
  476.     "",
  477.     "3 ファイルをアップする  ",
  478.     "",
  479.     "4 X-Modemでアップする   ",
  480.     NULL };
  481.  
  482.     wrtstr(SPCSTR,30,1,0x1F);
  483.     if ( Sel_menu(menu,30,2,&no) != FALSE )
  484.     goto ENDOF;
  485.  
  486.     if ( no == 0 ) {
  487.     ptr = 0;
  488.     sz = btm_ptr;
  489.     n = i = 0;
  490.     } else if ( no == 1 ) {
  491.     ptr = 0;
  492.     n = 0;
  493.     } else if ( no == 2 ) {
  494.     tmp[0] = '\0';
  495.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  496.         goto ENDOF;
  497.     if ( (fp = fopen(tmp,"rb")) == NULL ) {
  498.         wrtstr("(ファイルがオ-プン出来ません)",30,1,0x12);
  499.         goto ENDOF;
  500.     }
  501.     } else if ( no == 3 ) {
  502.     tmp[0] = '\0';
  503.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  504.         goto ENDOF;
  505.         RSB_init(port,mode & 0xEF,bps);
  506.     Up_Xmodem(tmp);
  507.         RSB_init(port,mode,bps);
  508.     goto ENDOF;
  509.     }
  510.  
  511.     wrtstr("アップロ-ド実行中",32,1,0x14);
  512.     Dsp_vram(cvram);
  513.     for ( ct = 0 ; ; ct++ ) {
  514.     if ( kbhit() != 0 ) {
  515.         ch = Get_key(&ec);
  516.         if ( ch == 0x1B || ec == 0x7200 )
  517.         break;
  518.     }
  519.     if ( no == 0 ) {
  520.         if ( i >= n ) {
  521.             if ( sz <= 0 )
  522.             break;
  523.         if ( sz < 256 ) n = sz; else n = 256;
  524.         Cut_buf(tmp,n,ptr);
  525.         ptr += n;
  526.         sz -= n;
  527.         i = 0;
  528.         }
  529.         ch = tmp[i++];
  530.     } else if ( no == 1 ) {
  531.         if ( n <= 0 ) {
  532.         if ( (n = Undo_cpy(tmp,256,ptr)) == 0 )
  533.             break;
  534.         p = tmp;
  535.         ptr += n;
  536.         }
  537.         ch = *(p++); n--;
  538.     } else if ( no == 2 ) {
  539.         if ( (ch = fgetc(fp)) == EOF )
  540.         break;
  541.     }
  542.     if ( ct > 50 ) {
  543.         recv_chk();
  544.         ct = 0;
  545.         }
  546.     if ( ch != '\x0A' && ch != '\x1A' )
  547.         Send_char(ch & 0xff);
  548.     }
  549.     if ( no == 3 )
  550.     fclose(fp);
  551.     wrtstr(SPCSTR,30,1,0x1F);
  552. ENDOF:
  553.     Dsp_vram(cvram);
  554.     Dsp_free();
  555. }
  556. void    RSB_end()
  557. {
  558.     if ( cvram != NULL )
  559.         RSB_close(port);
  560.     wrtstr("    ",10,0,0x1F);
  561.     free(cvram);
  562.     cvram = NULL; 
  563. }
  564. void    Line_edit(ch)
  565. int     ch;
  566. {
  567.     int    i;
  568.     static char tmp[180];
  569.  
  570.     if ( Line_flg == FALSE ) {
  571.     if ( ch != 0xFFFF )
  572.         Send_char(ch & 0xff);
  573.     if ( Line_X > 0 ) {
  574.         Line_X = 0;
  575.         memset(tmp,' ',80); tmp[80] = 0;
  576.         wrtstr(tmp,0,MAX_Y2+OFF_Y,0);
  577.         wrtstr(tmp,0,MAX_Y2+OFF_Y+1,0);
  578.     }
  579.     return;
  580.     }
  581.     if ( ch == 0x08 && Line_X > 0 ) {
  582.     Line_X--;
  583.     if ( &tmp[Line_X] != kanji_chk(tmp,Line_X) )
  584.        Line_X--;
  585.     } else if ( Line_X == 0 && ch < ' ' ) {
  586.     Send_char(ch & 0xff);
  587.     } else if ( ch != 0x08 && ch != 0x1B && ch != 0xFFFF )
  588.         tmp[Line_X++] = ch;
  589.     if ( Line_X >= 158 || ch == 0x0D || ch == 0x1B ) {
  590.     for ( i = 0 ; i < Line_X ; i++ )
  591.         Send_char(tmp[i] & 0xff);
  592.     if ( Line_X >= 80 ) {
  593.         memset(tmp,' ',80); tmp[80] = 0;
  594.         wrtstr(tmp,0,MAX_Y2+OFF_Y+1,0);
  595.     }
  596.     Line_X = 0;
  597.     }
  598.     tmp[Line_X] = 0xFE; tmp[Line_X+1] = 0x1B;
  599.     memset(tmp+Line_X+2,' ',164-Line_X);
  600.     tmp[161] = 0;
  601.     if ( Line_X < 80 )
  602.         tmp[81] = '\0';
  603.     wrtstr(tmp,0,MAX_Y2+OFF_Y,0x1D);
  604.     ReWrt_flg = (-2);
  605. }
  606. void    RSB_loop()
  607. {
  608.     int     ch,ef;
  609.     int     Bk_X,Bk_Y;
  610.     unsigned ec;
  611.  
  612.     wrtstr(SPCSTR,30,1,0x1F);
  613.     if ( cvram == NULL ) {
  614.         Test_RSB_mode();
  615.         RSB_init(port,mode,bps);
  616.     }
  617.     if ( Con_init() != FALSE ) {
  618.         RSB_close(port);
  619.     return;
  620.     }
  621.     wrtstr("通信",10,0,0x17);
  622.     Dsp_RSBKEY();
  623.  
  624.     for ( ef = FALSE ; ef == FALSE ; ) {
  625.     recv_chk();
  626.     for ( ; ; ) {
  627.         if ( Line_flg != FALSE ) {
  628.             Bk_X = Cur_X; Bk_Y = Cur_Y;
  629.             Cur_X = Line_X % 80; Cur_Y = MAX_Y2 + Line_X / 80;
  630.         if ( ReWrt_flg == ERR )
  631.             ReWrt_flg = TRUE;
  632.         }
  633.         if ( kbhit() != 0 )
  634.             ch = Get_key(&ec);
  635.         else
  636.         ec = 0xFFFF;
  637.         if ( Line_flg != FALSE ) {
  638.             Cur_X = Bk_X; Cur_Y = Bk_Y;
  639.         }
  640.         if ( ec == 0xFFFF )
  641.         break;
  642.         else if ( ec == 0x6600 )
  643.         ef = TRUE;
  644.         else if ( ec == 0x6500 )
  645.         ef = ERR;
  646.         else if ( ec == 0x5D00 )
  647.         Set_RSB_mode(1,2);
  648.         else if ( ec == 0x5E00 ) {
  649.         Line_flg = (Line_flg == FALSE ? TRUE : FALSE);
  650.         if ( Line_flg == FALSE )
  651.             Line_X = 1;
  652.         Line_edit(0xFFFF);
  653.         } else if ( ec == 0x5F00 )
  654.         Auto_log();
  655.         else if ( ec == 0x6100 ) {
  656. #ifdef    TOWNS
  657.         CD_menu();
  658. #endif
  659.             Dsp_vram(cvram);
  660.         } else if ( ec == 0x6200 )
  661.         Down_load();
  662.         else if ( ec == 0x6300 )
  663.         Up_load();
  664.         else if ( ec == 0x6400 )
  665.         RSB_break(port,brktime[brk]);
  666.         else if ( ch != 0xFFFF )
  667.         Line_edit(ch);
  668.     }
  669.     }
  670.     Con_end();
  671.     if ( Down_flg != FALSE )
  672.     Down_load();
  673.     if ( ef == ERR )
  674.     RSB_end();
  675.     else
  676.         wrtstr("通信",10,0,0x1F);
  677.     Dsp_PFKEY();    
  678.  
  679.     Line_flg = FALSE; Line_X = 1;
  680.     Line_edit(0xFFFF);
  681.  
  682.     wrtstr(SPCSTR,30,1,0x1F);
  683. }
  684.